<template>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item v-for="(item,index) in breadList" :key="item.path">
        <router-link to="/welcome" v-if="index ===0 ">{{item.meta.title}}</router-link>
        <span v-else>{{item.meta.title}}</span>
        
        </el-breadcrumb-item>
  </el-breadcrumb>
    
</template>
<!-- <script>
// import { getCurrentInstance,computed, ref,watch, reactive } from 'vue'
export default {
  name:'Breadcrumb',
  computed:{
      breadList(){
          return this.$router.currentRoute._rawValue.matched;
      }
  }
}
</script> -->


<script>
export default {
  data() {
    return {
      breadList: [],
    };
  },
  watch: {
    $route() {//监听$route
      this.getBreadcrumb();
    },
  },
  methods: {
    isHome(route) {
      return route.name === "home";
    },
    getBreadcrumb() {
      let matched = this.$route.matched;
      //如果不是首页
      if (!this.isHome(matched[0])) {
        matched = [].concat(matched);
      }
      this.breadList = matched;
    },
  },
  created() {
    //生命周期中调用获取数据的方法
    this.getBreadcrumb();
  },
};
</script>